<template>
  <div class="home-new" ref="target">
    <!-- 新鲜好物 -->
    <HomePanel title="人气推荐" sub-title="人气爆款 不容错过">
      <!-- 面板内容 -->
      <ul class="goods-list">
        <li v-for="item in goods" :key="item.id">
          <RouterLink to="/">
            <img v-imgLazy="item.picture" alt="" />
            <p class="name ellipsis">{{ item.title }}</p>
            <p class="name ellipsis">{{ item.alt }}</p>
          </RouterLink>
        </li>
      </ul>
    </HomePanel>
  </div>
</template>
<script>
// 引入懒加载组件
import { useLazyData } from '@/compositions/index.js'
import { ref } from 'vue'
import { findHot } from '@/api/home.js'
import HomePanel from './HomePanel.vue'

export default {
  name: 'HomeHot',
  components: { HomePanel },
  setup() {
    const goods = ref([])
    // 发起请求
    const fn = () => {
      findHot().then(data => {
        goods.value = data.result
      })
    }
    // 获取dom元素
    const target = useLazyData(fn)

    return { goods, target }
  }
}
</script>
<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
